package com.chushouya.controller.partner;

import com.chushouya.common.annotations.SignValidate;
import com.chushouya.common.constant.ServiceType;
import com.general.framework.core.schema.Response;
import com.general.framework.web.annotations.RepeatSubmit;
import com.chushouya.order.dto.api.order.OrderCancelApiDTO;
import com.chushouya.order.dto.api.order.OrderUserApiDTO;
import com.chushouya.order.dto.partner.order.OrderSubmitPartnerDTO;
import com.chushouya.order.service.api.UserOrderActionService;
import com.chushouya.order.service.partner.OrderPartnerApiService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import javax.validation.Valid;


@Slf4j
@Api(tags = ServiceType.OPENAPI + "平台订单管理")
@RestController
@RequestMapping(ServiceType.OPENAPI + "/order")
public class OrderPartnerController {


    @Resource
    private OrderPartnerApiService orderPartnerApiService;

    @Resource
    private UserOrderActionService userOrderActionService;

    @ApiOperation("创建订单接口")
    @PostMapping("/submit")
    @RepeatSubmit
    @SignValidate
    public Response<OrderUserApiDTO> orderCreate(@RequestBody @Validated OrderSubmitPartnerDTO data) {
        return Response.success(orderPartnerApiService.submitOrder(data));
    }

    @ApiOperation("取消订单接口")
    @PostMapping("/cancel")
    @SignValidate
    public Response orderCancel(@RequestBody @Valid OrderCancelApiDTO orderCancel) {
        userOrderActionService.cancelOrder(orderCancel);
        return Response.success("取消成功");
    }



}
